<template>
<div id="example">
    <p>{{ message }}</p>
    <input type='text' v-model="money | filterMoney '￥' 0 " ></div>
</div>

</template>
<style scoped>
	input{
		color:black;
	}
</style>
<script>

import Vue          from 'vue';

Vue.filter('filterMoney', {
    // model -> view
    // 在更新 `<input>` 元素之前格式化值
    read: function(val,place) {
   		console.log("read",val.formatMoney(place, '￥'))
        if (val==="")  return false;
        return val.formatMoney(place, '￥');
    },
    // view -> model
    // 在写回数据之前格式化值
    write: function(val, oldVal) {
	    console.log("write")
	    if (!val)  return false;

	    return parseFloat(val.replace(/[^0-9-.]/g, ''));
    }
});

export default{
	data(){
		return {
			money:123
		}
	},
	watch:{
		'money':function(val, oldVal){
			console.log('watch',val, oldVal)
		}
	}
}

</script>